package main;

import java.awt.Graphics2D;
import java.awt.image.ImageObserver;

import binarySearchTree.BinaryNode;
import binarySearchTree.BinarySearchTree;

public class DrawTree {
	
	private BinarySearchTree<Sprite> drawTree;
	private boolean reBuildFlag = false;
	
	public DrawTree(){
		createDrawTree();		
	}
	
	public void createDrawTree(){
		
		this.drawTree = new BinarySearchTree<Sprite>();
		
	}
	
	public void setReBuildFlag(boolean x){
		this.reBuildFlag = x;		
	}
	public boolean getReBuildFlag(){
		return this.reBuildFlag;		
	}
	public boolean reBuildFlag(){
		return this.reBuildFlag;		
	}
	
	public boolean isEmpty(){
		return drawTree.isEmpty();
	}
	
	public void insert(Sprite s){
		if(isEmpty()){
			createDrawTree();			
		}
		drawTree.insert(s);				
	}
	
	public void draw(Graphics2D g, ImageObserver imgObserver ){
		this.my_draw(g, imgObserver, drawTree.getRoot());
	}
	
	private void my_draw(Graphics2D g,ImageObserver imgObserver, BinaryNode x){
		if(x == null)
		        return;
		my_draw(g, imgObserver, x.getLeft());
		x.setLeft(null);
		Sprite s = (Sprite) x.getElement();
		s.setG(g);
		s.setImgObserver(imgObserver);
		s.draw();		
		my_draw(g,imgObserver, x.getRight());
		x.setRight(null);
		

		
		
		
	}
	
	
	

}
